<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"></meta>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"></meta>
<title>列表</title>
<span th:replace="common-easyui-mobile::easyui_mobile_js_css"></span>
</head>
<body>
<link th:href="@{/js/jquery-easyui-1.7.5/themes/metro/easyui.css}" rel="stylesheet" media="screen"/>
<link th:href="@{/js/jquery-easyui-1.7.5/themes/mobile.css}" rel="stylesheet" media="screen"/>
<link th:href="@{/js/jquery-easyui-1.7.5/themes/color.css}" rel="stylesheet" media="screen"/>
<link th:href="@{/js/jquery-easyui-1.7.5/themes/icon.css}" rel="stylesheet" media="screen"/>
<link th:href="@{/font-awesome-4.7.0/css/font-awesome.min.css}" rel="stylesheet" media="screen"/>


<script th:src="@{/js/jquery-easyui-1.7.5/jquery.min.js}" type="text/javascript"></script>
<script th:src="@{/js/jquery-easyui-1.7.5/jquery.easyui.min.js}" type="text/javascript"></script>
<script th:src="@{/js/jquery-easyui-1.7.5/jquery.easyui.mobile.js}" type="text/javascript"></script>
<script th:src="@{/js/jquery-easyui-1.7.5/plugins/datagrid-detailview.js}" type="text/javascript"></script>
<script th:src="@{/js/jquery-easyui-1.7.5/plugins/jquery.easyui.iplugin.js}" type="text/javascript"></script>





<script th:inline="javascript">
	//<![CDATA[
	var ctx = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;
	//定义集合
	var calcStockArray=[];           
	           
	function getStockInfoFromWsByCode(code,buyPrice,buyCount,displayOrder){
		$.ajax({
		    url:"http://hq.sinajs.cn/list="+code,
		    dataType:"script",
		    cache:"false",
		    type:"GET",
		    success:function(a){
		    	  var result = eval('hq_str_'+code);
		    	  console.info(result)
		    	  var resultArray=result.split(',');
		    	  var netStockInfo=new Object();
		    	  netStockInfo.code=code;
		    	  netStockInfo.name=resultArray[0];
		    	  netStockInfo.startPrice=resultArray[1];
		    	  netStockInfo.yesterdayPrice=resultArray[2];
		    	  netStockInfo.currentPrice=resultArray[3];
		    	  netStockInfo.maxiPrice=resultArray[4];
		    	  netStockInfo.miniPrice=resultArray[5];
		    	  netStockInfo.buyPrice=buyPrice;
		    	  netStockInfo.buyCount=buyCount;
		    	  netStockInfo.displayOrder=displayOrder;
		    	
		    	  netStockInfo.dayFlPercent=((((netStockInfo.currentPrice-netStockInfo.yesterdayPrice)/netStockInfo.yesterdayPrice))*100).toFixed(3);
		    	  if(code.indexOf('000001')>-1){
		    		  netStockInfo.dayFl=((netStockInfo.currentPrice-netStockInfo.yesterdayPrice).toFixed(2));
		    		  netStockInfo.sumFl=(((netStockInfo.currentPrice-buyPrice))*buyCount).toFixed(0);
		    	  }else{
		    		  netStockInfo.dayFl=((netStockInfo.currentPrice-netStockInfo.yesterdayPrice).toFixed(2))*100;
		    		  netStockInfo.sumFl=(((netStockInfo.currentPrice-buyPrice))*buyCount*100).toFixed(0);
		    	  }
		    	  
		    	  netStockInfo.daySumFl=(netStockInfo.dayFl)*buyCount;
		    	  netStockInfo.flPercent=((((netStockInfo.currentPrice-buyPrice)/buyPrice))*100).toFixed(3);
		    	  
		    	  calcStockArray.push(netStockInfo);
		    	  //netStockInfo.currentFiveDayPrice='';
		    	  //netStockInfo.tomorrowFiveDayPrice='';
		    	  // return netStockInfo;
		        }
		    });
	
	}
	
	
	function getStockList(){
		$.ajax({
	        type: "POST",
	        url:ctx+'/stock/getPagerList',
	        data: {
	        	page:'1',
	        	rows:'1000'
	        },
	        success: function (data) {
	        	calcStockArray.length=0;
	        	for(var i=0;i<data.rows.length;i++){
	        		getStockInfoFromWsByCode(data.rows[i].code,data.rows[i].buyPrice,data.rows[i].buyCount,data.rows[i].displayOrder);
	        	}
	        },
	        error: function(data) {
	            alert("error:"+data.responseText);
	         }
	  		});
		
	}
	
	getStockList();
	
	function loadGrid(){
		//排序
		calcStockArray.sort(function(a,b){ return parseInt(a.displayOrder)-parseInt(b.displayOrder)});
		
		$('#dgTable').datagrid({  
			//url:ctx+'/stock/list',
			data:calcStockArray,
		    queryParams: {
			},
			fit:true,
			pageSize: 10,
			fitColumns:true,
			striped: true,
			singleSelect:true,
			pagination: false,  
			rownumbers: true,
			scrollbarSize:0,
			columns:[[
			          {field:'id',title: '栏目',align: 'center',width: 58,hidden:true},
			          {field:'code',title: '代码',align: 'center',width: 65},
			          {field:'name',title: '名称',align: 'center',width: 60}, 
			          {field:'startPrice',title: '今开',align: 'center',width: 60} , 
			          {field:'miniPrice',title: '最低',align: 'center',width: 60}  , 
			          {field:'maxiPrice',title: '最高',align: 'center',width: 60}, 
			          {field:'yesterdayPrice',title: '昨收',align: 'center',width: 60} , 
			          {field:'currentPrice',title: '当前价',align: 'center',width: 60,formatter:function(val,rec){
			        		if(parseFloat(val)>0){
								return '<span style="color:red">'+val+'</span>'		        		 
				        	 }else{
				        		return '<span style="color:green">'+val+'</span>'
				        	 }
				       }} , 
				       	//{field:'currentFiveDayPrice',title: '5日线',align: 'center',width: 60} , 
				       	//{field:'tomorrowFiveDayPrice',title: '明天5日线',align: 'center',width: 60} , 
			          {field:'dayFl',title: '当日盈亏',align: 'center',width: 60,formatter:function(val,rec){
			        	 if(parseFloat(val)>0){
							return '<span style="color:red">'+val+'</span>'		        		 
			        	 }else{
			        		return '<span style="color:green">'+val+'</span>'
			        	 }
			          }} ,      
			          {field:'dayFlPercent',title: '比率',align: 'center',width: 60,formatter:function(val,rec){
				        	 if(parseFloat(val)>0){
									return '<span style="color:red">'+val+'%'+'</span>'		        		 
					        	 }else{
					        		return '<span style="color:green">'+val+'%'+'</span>'
					        	 }
					  }} ,  
			          {field:'buyCount',title: '数量',align: 'center',width: 60}, 
			          {field:'daySumFl',title: '当日总盈亏',align: 'center',width: 60,formatter:function(val,rec){
				        	 if(parseFloat(val)>0){
									return '<span style="color:red">'+val+'</span>'		        		 
					        	 }else{
					        		return '<span style="color:#228B22">'+val+'</span>'
					        	 }
					  }} , 
			          {field:'buyPrice',title: '买入价',align: 'center',width: 60}, 
			          {field:'flPercent',title: '总比率',align: 'center',width: 60,formatter:function(val,rec){
				        	 if(parseFloat(val)>0){
									return '<span style="color:red">'+val+'%'+'</span>'		        		 
					        	 }else{
					        		return '<span style="color:#228B22">'+val+'%'+'</span>'
					        	 }
					  }} ,    
			          {field:'sumFl',title: '总盈亏',align: 'center',width: 60},    
			          {field:'currentFiveDayPrice',title: '5日线',align: 'center',width: 60,formatter:function(val,rec){
				        	return "<a title='查看' href='javascript:void(0)' onclick=showFiveLineWin('"+rec.id+"')>查看</a>";

			          }
			          }
			]]
			,toolbar:$('#tb')
		  });
	}
	
	setTimeout("loadGrid()",1000);
	
	
	
	 var refreshEvent;
	 var timer_is_on = 0;
	 function refreshPage(){
		 refreshEvent= setTimeout(function(){location.reload()},10000); 
	 }
	 //开始刷新页面
	 function startRefresh(){
		 if (!timer_is_on) {
		      timer_is_on = 1;
		      refreshPage();
		  }
	 }
	 
	 //停止刷新页面
	 function stopRefresh(){
		 clearTimeout(refreshEvent);
		 timer_is_on = 0;
	 }
	 
	 startRefresh();
	
	
	//]]>
</script>

	






<table id="dgTable">
	</table>
	<div id="tb">
		<div class="m-toolbar">
			<div class="m-title">
				
			</div>
			 <div class="m-left">
                    <a th:href="@{/index}" class="easyui-linkbutton m-back" plain="true" outline="true">首页</a>
                </div>
                
              <div class="m-right">
                    <a th:href="@{/add}" class="easyui-linkbutton"  plain="true" outline="true">添加</a>
                </div>   
		</div>
	</div>

</body>
</html>